package fun.qu_an.minecraft.fabric.fzbbl.mixin;

import fun.qu_an.minecraft.fabric.fzbbl.event.ScoreboardEvents;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreboardCriterion;
import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Scoreboard.class)
public class ScoreboardMixin {
    @Inject(at = @At(value = "RETURN"), method = "addObjective")
    public void onScoreboardAdded(final String name, final ScoreboardCriterion criterion, final Text displayName, final ScoreboardCriterion.RenderType renderType, CallbackInfoReturnable<ScoreboardObjective> cir) {
        ScoreboardObjective objective = cir.getReturnValue();
        ScoreboardEvents.ADDED.invoker().interact(objective);
    }

    @Inject(at = @At(value = "RETURN"), method = "removeObjective")
    public void onScoreboardRemoved(final ScoreboardObjective objective, CallbackInfo ci) {
        ScoreboardEvents.REMOVED.invoker().interact(objective);
    }
}
